package com.cloudptt.api.product.func.media.device;

import java.util.Iterator;
import java.util.Set;

import com.cloudptt.api.comm.Const;
import com.cloudptt.api.product.func.media.EventListener;
import com.cloudptt.api.product.log.Log;

import android.bluetooth.BluetoothHeadset;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.KeyEvent;

public class DefaultDevKey implements IDeviceKey {

	public DefaultDevKey(){
		
	}

	public final static String THIS_FILE = "PNC370";
	private long pttOnTimer =  0;

	private IntentFilter mFilter;
	private final static String ACTION_BRAST = "com.meigsmart.meigkeyaccessibility.onkeyevent";


	public static boolean isThisDev(String brand,String device,String model){
		return false;
	}

	@Override
	public IntentFilter getBstIntentFilter() {
		Log.d(THIS_FILE, "getBstIntentFilter");
		mFilter = new IntentFilter();
		/**蓝牙PTT**/
		mFilter.addAction(ACTION_BRAST);/**蓝牙指环PTT**/

		return mFilter;
	}

	@Override
	public void procBst(Intent intent, EventListener listener) {
		String action = intent.getAction();
		Log.d(THIS_FILE, " procBst action = " + action);
		if(action.equals(ACTION_BRAST)){
			int actionKey = intent.getIntExtra("action", -1);
			int keycode = intent.getIntExtra("keycode", -1);
//这里可以对按键做你想要的处理
			if(KeyEvent.KEYCODE_F12 == keycode) {
				if (actionKey == KeyEvent.ACTION_DOWN) {
					if (listener != null) {
						listener.onPtt(Const.MSG_TALK_ON, false, true);
					}
				} else if (actionKey == KeyEvent.ACTION_UP) {
					if (listener != null) {
						listener.onPtt(Const.MSG_TALK_OFF, false, true);
					}
				}
			}
			else if(KeyEvent.KEYCODE_F2 == keycode) {
				if (actionKey == KeyEvent.ACTION_DOWN) {
					pttOnTimer = System.currentTimeMillis();
				}
				else if (actionKey == KeyEvent.ACTION_UP) {
					long val = System.currentTimeMillis();
					boolean isLongPress = (val - pttOnTimer) > 2000;
					if (listener != null) {
						listener.onSOS(isLongPress);
					}
				}
			}
		}
	}
}
